package com.zhongyu.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhongyu.pojo.User;
import javafx.scene.control.Pagination;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserMapper extends BaseMapper<User> {


   /* List<User> findAll(Wrapper wrapper);*/

    @Select("SELECT t1.*,t2.id AS role_id,t2.*,t3.id AS org_id, t3.*  FROM smbms_user t1 LEFT  JOIN smbms_role t2 ON t1.user_role=t2.id JOIN smbms_org t3 ON t1.user_org=t3.id ${ew.customSqlSegment}")
    @ResultMap("userRm")

    List<User> findAll(Page page, @Param("ew") Wrapper wrapper);
    @Select("SELECT user_role FROM smbms_user WHERE id=#{userRole}")
    List<Integer> userRole(@Param("userRole") Integer userRole);
    @Select("UPDATE smbms_user SET user_role=#{userRole} WHERE id=#{userId}")
    void update(@Param("userId") Integer userId,@Param("userRole") Integer userRole);
    @Select("UPDATE smbms_user SET password=#{newPas} WHERE username=#{username}")
    void up(@Param("newPas") String newPas,@Param("username")String  username);
    @Select("select user_code from smbms_user where user_code=#{userCode}")
    String selectUserCode(String userCode);
    @Select("SELECT PASSWORD FROM smbms_user WHERE PASSWORD=#{password} AND username=#{username}")
    String selectPassword(@Param("password") String password,@Param("username") String username);
    @Select("UPDATE smbms_user SET PASSWORD = #{password} where user_code=#{userCode}")
    void updatePwd(@Param("password") String password,@Param("userCode") String userCode);

}
